package org.cwgl.actions;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.cwgl.interfaces.BaseDataService;
import org.cwgl.util.Json;
import org.cwgl.vo.Result;
import org.cwgl.vo.StandbookVo;

public class StandbookAction {

	public StandbookVo standbook=new StandbookVo();
	public BaseDataService service;
	
	
	public BaseDataService getService() {
		return service;
	}

	public void setService(BaseDataService service) {
		this.service = service;
	}

	public StandbookVo getStandbook() {
		return standbook;
	}

	public void setStandbook(StandbookVo standbook) {
		this.standbook = standbook;
	}

	/**
	 * 添加台账对象
	 * @return
	 * @throws IOException 
	 */
	public String addStandbook()
	{
		Result result = new Result();
		result.setSuccess(false);
		HttpServletResponse response = ServletActionContext.getResponse();
		PrintWriter out = null;
		try 
		{
			out = response.getWriter();
			result.setSuccess(true);
		} catch (IOException e) 
		{
			result.setException(e.getMessage());
		} finally 
		{
			if (result.getSuccess() == true) {
				result = service.addStandbook(this.standbook);
			}
			out.print(Json.JSON_Object(result));
			out.flush();
		}
		return (null);
	}
	
	/**
	 * 更新台账
	 * @return
	 */
	public String updateStanbook()
	{
		Result result = new Result();
		result.setSuccess(false);
		HttpServletResponse response = ServletActionContext.getResponse();
		PrintWriter out = null;
		try 
		{
			out = response.getWriter();
			result.setSuccess(true);
		} catch (IOException e) 
		{
			result.setException(e.getMessage());
		} finally 
		{
			if (result.getSuccess() == true) {
				result = service.updateStandbook(this.standbook);
			}
			out.print(Json.JSON_Object(result));
			out.flush();
		}
		return (null);
	}
	
	/**
	 * 删除台账
	 * @return
	 */
	public String delStandbook()
	{
		Result result = new Result();
		result.setSuccess(false);
		HttpServletResponse response = ServletActionContext.getResponse();
		PrintWriter out = null;
		try 
		{
			out = response.getWriter();
			result.setSuccess(true);
		} catch (IOException e) 
		{
			result.setException(e.getMessage());
		} finally 
		{
			if (result.getSuccess() == true) {
				result = service.deleteStandbook(this.standbook);
			}
			out.print(Json.JSON_Object(result));
			out.flush();
		}
		return (null);
	}
}
